/**
 * 
 */
package top.lcpsky.flashcards.dto;

import java.math.BigDecimal;

import lombok.Data;
import top.lcpsky.flashcards.entity.SharesDaily;

/**   
 * @ClassName:  StockSimpleInfo   
 * @author: lcp
 * @date:   2020年7月17日 下午6:28:34   
 *     
 * @Copyright: 2020 www.ankept.com Inc. All rights reserved. 
 */
@Data
public class StockSimpleInfo {
	private String code;
	private String name;
	private Double price;
	private Double upDownAmount;
	private Double upDownRate;
	
	
	public StockSimpleInfo(SharesDaily rtInfoByCode) {
		this.code = rtInfoByCode.getShares().getCode();
		this.name = rtInfoByCode.getShares().getName();
		this.price = rtInfoByCode.getEndPrice();
		this.upDownAmount = parse(rtInfoByCode.getStartPrice()-rtInfoByCode.getEndPrice());
		this.upDownRate = parse(upDownAmount/rtInfoByCode.getStartPrice());
	}
	
	private static Double parse(Double d) {
		BigDecimal b = new BigDecimal(d);
		d = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();    
		return d;
	}
}
